<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/5/23 0023
 * Time: 16:32
 */

namespace app\wap\controller;


use Firebase\JWT\JWT;
use think\Db;
use think\Request;

class Middle extends Base
{
    public $uid;
    public $vip;
    public $vip_expire;
    public $invitation;
  	public $reg_id;
    public function __construct()
    {
        parent::__construct();
        $Key = config('LOGINKEY');
        //$token = Request::instance()->header('token');
        $token = input('token');
        if(!$token)exit($this->encode('请登录'));
        $ref = JWT::decode($token,$Key,['HS256']);
        if(!$token || !is_object($ref))exit($this->encode('登录信息错误,请重新登录'));
		$user = Db::name('user')->where(['uid'=>$ref->uid])->find();
      	if($token != $user['token'])exit($this->encode('登录信息错误,请重新登录'));
        $this->uid = $ref->uid;
        $this->invitation = $ref->code;
      	$this->reg_id = $ref->reg_id;
        $map = ['uid'=>$this->uid];
        $ref = Db::name('user_service')->where($map)->find();
      	Db::name('user')->where($map)->update(['update_time'=>time()]);
        $this->vip = $ref['vip'];
        $this->vip_expire = $ref['expire'];
    }
}